#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+5;
int n,m,vis[maxn],dfn[maxn];
vector<pair<int,int> > e[maxn],Tr[maxn];
int u[maxn],v[maxn],ont[maxn],q,sze[maxn],T[maxn];
void dfs(int u){
	vis[u]=1;
	for(auto [v,id]:e[u]){
		if(!vis[v]){
			Tr[u].push_back({v,id});
			ont[id]=1;dfs(v);
		}
	}
}
void dfs2(int u){
	dfn[u]=++dfn[0];sze[u]=1;
	for(auto [v,id]:Tr[u])dfs2(v),sze[u]+=sze[v];
}
int ed[maxn/2][21],cnt[maxn/2][21][21];
struct intv{int l,r,id;};
bool operator <(intv a,intv b){return a.r<b.r;}
int K[maxn];
bool cmp(int a,int b){return dfn[u[a]]<dfn[u[b]];}
struct query{int x,y,tp,id,p1,p2;};
vector<query> Q(1);
namespace BIT{
	int c[maxn];
	void add(int p,int v){for(;p<=n;p+=p&-p)c[p]+=v;}
	int ask(int p){int ans=0;for(;p;p-=p&-p)ans+=c[p];return ans;}
}
using namespace BIT;
vector<int> eq[maxn],ead[maxn];
int fa[maxn];
int Find(int x){return x==fa[x]?x:fa[x]=Find(fa[x]);}
signed main(){
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u[i]>>v[i];
		e[u[i]].push_back({v[i],i});
		e[v[i]].push_back({u[i],i});
	}
	dfs(1);dfs2(1);
	for(int i=1;i<=m;i++){
		if(dfn[u[i]]>dfn[v[i]])swap(u[i],v[i]);
		if(!ont[i])ead[dfn[u[i]]].push_back(dfn[v[i]]);//,cerr<<dfn[u[i]]<<"-"<<dfn[v[i]]<<endl;
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		// cerr<<"______________________________________________"<<endl;
		cin>>K[i];
		set<intv> st;
		for(int j=1;j<=K[i];j++)cin>>ed[i][j];
		sort(ed[i]+1,ed[i]+1+K[i],cmp);
		st.insert({1,n,1});T[i]=1;
		vector<int> vec;
		for(int j=1;j<=K[i];j++){
			if(!ont[ed[i][j]]){vec.push_back(ed[i][j]);continue;}
			++T[i];
			int L=dfn[v[ed[i][j]]],R=dfn[v[ed[i][j]]]+sze[v[ed[i][j]]]-1;
			auto it=*st.lower_bound({L,R});int l=it.l,r=it.r,id=it.id;
			st.erase(it);
			st.insert({L,R,T[i]});
			if(L>l)st.insert({l,L-1,id});
			if(R<r)st.insert({R+1,r,id});
		}
		vector<intv> V;
		for(auto u:st)V.push_back(u);//,cerr<<u.l<<","<<u.r<<" id = "<<u.id<<endl;
		for(int j=1;j<V.size();j++){
			if(V[j].id==-1)continue;
			for(int k=0;k<j;k++){
				if(V[j].id==V[k].id||V[k].id==-1)continue;
				int l1=V[k].l,r1=V[k].r,l2=V[j].l,r2=V[j].r;
				Q.push_back({r1,r2,1,i,V[k].id,V[j].id});
				Q.push_back({l1-1,r2,-1,i,V[k].id,V[j].id});
				Q.push_back({r1,l2-1,-1,i,V[k].id,V[j].id});
				Q.push_back({l1-1,l2-1,1,i,V[k].id,V[j].id});
				int p1=V[k].id,p2=V[j].id;
				if(p1>p2)swap(p1,p2);
				for(auto t:vec)if(l1<=dfn[u[t]]&&dfn[u[t]]<=r1&&l2<=dfn[v[t]]&&dfn[v[t]]<=r2)cnt[i][p1][p2]--;
			}
		}
	}
	for(int i=1;i<Q.size();i++)eq[Q[i].x].push_back(i);
	for(int i=1;i<=n;i++){
		for(auto y:ead[i])add(y,1);//,cerr<<"add "<<y<<endl;
		for(auto u:eq[i]){
			if(Q[u].p1>Q[u].p2)swap(Q[u].p1,Q[u].p2);
			cnt[Q[u].id][Q[u].p1][Q[u].p2]+=Q[u].tp*ask(Q[u].y);
			// if(Q[u].id==4)cerr<<"Found to be += "<<Q[u].tp*ask(Q[u].y)<<"(y="<<Q[u].y<<")"<<endl;
		}
	}	
	for(int i=1;i<=q;i++){
		for(int j=1;j<=T[i];j++)fa[j]=j;
		for(int j=1;j<=T[i];j++){
			for(int k=j+1;k<=T[i];k++){
				if(cnt[i][j][k]>0)fa[Find(j)]=Find(k);
			}
		}
		bool flg=1;
		for(int j=1;j<=T[i];j++)if(Find(j)!=Find(1)){flg=0;break;}
		if(flg)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}
